/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package hxg.portmgr.core.device;

import hxg.portmgr.core.oper.Oper;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

/**
 *
 * @author hxg
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {})
@XmlRootElement(name = "DeviceModel")
public class DeviceModel implements Comparable<DeviceModel> {

    private static final Logger logger = Logger.getLogger(DeviceModel.class.getName());
    private static final DeviceModel unReachAbleModel = new DeviceModel();

    static {
        unReachAbleModel.setType(DeviceType.OTHER);
        unReachAbleModel.setModelName("不可到达");
        unReachAbleModel.setSysOid("不可到达");
    }

    public static DeviceModel getUnReachedAbleModel() {
        return unReachAbleModel;
    }

    public enum IntfMark {

        Self, Name, Desc, Index, All;

        @Override
        public String toString() {
            switch (this) {
                case Self:
                    return "自定义";
                case Name:
                    return "接口名[ifName]";
                case Desc:
                    return "接口描叙[ifDesc]";
                case Index:
                    return "接口ID[ifIndex]";
                case All:
                    return "全部信息显示";
            }
            return "未知";
        }
    }
    @XmlAttribute
    long id;
    @XmlElement
    String sysOid = "0";
    @XmlAttribute
    String modelName = "";
    @XmlElement
    hxg.portmgr.core.device.DeviceType type = DeviceType.OTHER;
    //private Class<? extends oper> operclass = null; //如果为null,具体返回时返回DefaultSnmpOper
    @XmlElement
    String operName = "";
    @XmlElement
    IntfMark IntfMarkFromAttr = IntfMark.All;

    public String getModelName() {
        return modelName;
    }

    public void setModelName(String model) {
        this.modelName = model;
    }

    public Class<? extends Oper> getOperclass() {
        Class<? extends Oper> operc = null;
        if (operName == null || operName.isEmpty()) {
            return operc;
        }
        try {
            operc = (Class<? extends Oper>) Class.forName(operName);
        } catch (ClassNotFoundException ex) {
            logger.log(Level.SEVERE, "没有发现类{0}", operName);
        }
        return operc;
    }

    //public void setOperclass(Class<? extends SnmpOper> operclass) {
    //    this.operclass = operclass;
    //}
    public String getOperName() {
        return operName;
    }

    public void setOperName(String operName) {
        this.operName = operName;
    }

    public String getSysOid() {
        return sysOid;
    }

    public void setSysOid(String sysOid) {
        this.sysOid = sysOid;
    }

    public DeviceType getType() {
        return type;
    }

    public void setType(DeviceType type) {
        this.type = type;
    }

    public IntfMark getIntfMarkFromAttr() {
        return IntfMarkFromAttr;
    }

    public void setIntfMarkFromAttr(IntfMark IntfMarkFromAttr) {
        this.IntfMarkFromAttr = IntfMarkFromAttr;
    }

    @Override
    public String toString() {
        return (this.modelName == null || this.modelName.isEmpty())
                ? sysOid : this.modelName;
    }

    @Override
    public int compareTo(DeviceModel o) {
        return this.getSysOid().compareTo(o.getSysOid());
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (!(obj instanceof DeviceModel)) {
            return false;
        } else {
            String osysOid = ((DeviceModel) obj).getSysOid();
            return osysOid.equals(sysOid);
        }
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 79 * hash + (this.sysOid != null ? this.sysOid.hashCode() : 0);
        return hash;
    }
}
